package com.zjgs.onlinepdfeditor.mapper;

import com.zjgs.onlinepdfeditor.entity.FileEntity;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Component;


import java.util.List;

@Component
@Mapper
public interface FileMapper {
    @Select("SELECT * FROM files")
    @Results({
            @Result(property = "id", column = "id"),
            @Result(property = "fileName", column = "file_name"),
            @Result(property = "filePath", column = "file_path")
    })
    List<FileEntity> getAll();

    @Select("SELECT * FROM files WHERE id = #{id}")
    @Results({
            @Result(property = "id", column = "id"),
            @Result(property = "fileName", column = "file_name"),
            @Result(property = "filePath", column = "file_path")
    })
    FileEntity getOne(String id);

    @Insert("INSERT INTO files(id,file_name,file_path,file_uploadtime) VALUES(#{id},#{fileName},#{filePath},#{fileUploadtime})")
    void insert(FileEntity file);

    @Update("UPDATE files SET file_name=#{fileName},file_path=#{filePath} WHERE id =#{id}")
    boolean update(FileEntity file);

    @Delete("DELETE FROM files WHERE id =#{id}")
    void delete(String id);
}
